//
//  CLViewController.m
//  CLExtension
//
//  Created by CharlieLiao on 2017/7/3.
//  Copyright © 2017年 Charlie. All rights reserved.
//

#import "CLViewController.h"



@interface CLViewController ()
@end

@implementation CLViewController

//
- (void)setView:(UIView*)view
{
    BOOL viewNotLoad = ![self isViewLoaded];
    if (viewNotLoad) { // view还未加载，开始加载自定义view
        
        if ([self.class respondsToSelector:@selector(viewClass)]) {
            Class class = [self.class viewClass]; // 自定义view
            view = [(UIView*)[class alloc] initWithFrame:view.frame];
        }
    }
    
    [super setView:view];
    
    if (viewNotLoad && [view conformsToProtocol:@protocol(CustomViewProtocol)]) {
        if ([view respondsToSelector:@selector(initSetupSubviews)])
            [(id <CustomViewProtocol>)view initSetupSubviews];
        if ([view respondsToSelector:@selector(makeSubViewConstraints)])
            [(id <CustomViewProtocol>)view makeSubViewConstraints];
        if ([view respondsToSelector:@selector(setupOutlets:)])
            [(id <CustomViewProtocol>)view setupOutlets:self];
        if ([view respondsToSelector:@selector(setupReferencingOutlets:)])
            [(id <CustomViewProtocol>)view setupReferencingOutlets:self];
        if ([view respondsToSelector:@selector(setupReceivedActions:)])
            [(id <CustomViewProtocol>)view setupReceivedActions:self];
    }
}

@end
